require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'

module MyMarkDown

	class Renderer < Redcarpet::Render::HTML
		include Rouge::Plugins::Redcarpet

		def initialize(extensions = {})

			super(extensions.merge(xhtml: true,
			                       no_styles: true,
			                       escape_html: true,
			                       hard_wrap: true,
			                       link_attributes: { target: '_blank' }))
		end

	end


	class Markdowns
		include Singleton

		def self.converter(text)
			instance.converter(text)
		end

		def converter(text)
 				@converter.render(text)
		end

		private
			def initialize
				opts = {
					autolink: true,
					fenced_code_blocks: true,
					strikethrough: true,
					tables: true,
					space_after_headers: true,
					disable_indented_code_blocks: true,
					no_intra_emphasis: true
				}

				renderer = MyMarkDown::Renderer.new
				@converter = Redcarpet::Markdown.new(renderer, opts)
			end


	end

end